<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      // 随便写写，没经过什么思考，欢迎指正和重写
      // 保存下全局的 console 对象，防止被别人重写，比如在 alita 的某一些场景中，会通过暴力覆盖它来达到去除项目中的console的目的
      // 通过全局的 alitadebug 来控制是否打印日志
      let chalk = {};
      if (!window.chalk) {
        const _console = console;
        const color = {
          black: '#000000',
          red: '#FF0000',
          green: '#008000',
          yellow: '#FFFF00',
          blue: '#0000FF',
          magenta: '#FF00FF',
          cyan: '#00FFFF',
          white: '#FFFFFF',
        };
        // @ts-ignore
        const add = (...arr) => {
          let fi = [[]];
          for (let key = 0; key < arr.length; key++) {
            const [first, ...other] = arr[key];
            fi[0] += first;
            fi = fi.concat(other);
          }
          return fi;
        };
        const createlog =
          (util) =>
          (
            // @ts-ignore
            ...args
          ) => {
            const fun = _console[util] ? _console[util] : _console.log;
            window.alitadebug && fun.apply(void 0, args);
          };
        const colorUtils = {
          bold: (str) => {
            if (typeof str === 'string' || typeof str === 'number') {
              return `${str};font-weight: bold;`;
            }
            for (let key = 1; key < str.length; key++) {
              str[key] += `;font-weight: bold;`;
            }
            return str;
          },
        };
        const colorHash = {
          log: 'black',
          wait: 'cyan',
          error: 'red',
          warn: 'yellow',
          ready: 'green',
          info: 'blue',
          event: 'magenta',
          debug: 'gray',
        };
        const createChalk =
          (name) =>
          (...str) => {
            if (typeof str[0] === 'object') {
              createlog(name)(
                ...add(
                  colorUtils.bold(
                    colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `),
                  ),
                  ...str,
                ),
              );
              return;
            }
            let strArr = str;
            if (typeof str === 'string' || typeof str === 'number') {
              strArr = colorUtils[colorHash[name]](str);
            }
            createlog(name)(
              ...add(
                colorUtils.bold(
                  colorUtils[colorHash[name]](`[${firstToUpperCase(name)}] `),
                ),
                strArr,
              ),
            );
          };
        const chalk = {};
        Object.keys(colorHash).forEach((key) => {
          chalk[key] = createChalk(key);
        });
        const firstToUpperCase = (str) =>
          str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
        Object.keys(color).forEach((key) => {
          colorUtils[key] = (str) => {
            if (typeof str === 'string' || typeof str === 'number') {
              return [`%c${str}`, `color:${color[key]}`];
            }
            for (let i = 1; i < str.length; i++) {
              str[i] += `;color:${color[key]}`;
            }
            return str;
          };
          colorUtils[`bg${firstToUpperCase(key)}`] = (str) => {
            if (typeof str === 'string' || typeof str === 'number') {
              return [
                `%c${str}`,
                `padding: 2px 4px; border-radius: 3px; color: ${
                  key === 'white' ? '#000' : '#fff'
                }; font-weight: bold; background:${color[key]};`,
              ];
            }
            for (let i = 1; i < str.length; i++) {
              str[
                i
              ] += `;padding: 2px 4px; border-radius: 3px; font-weight: bold; background:${color[key]};`;
            }
            return str;
          };
        });
        window.chalk = {
          add,
          ...chalk,
          ...colorUtils,
          hello: (title, version) =>
            createlog('log')(
              `%c ${title} %c V${version} `,
              'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;',
              'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;',
            ),
          image: (img) => {
            if (!img) return;
            createlog('log')(
              `%c `,
              `font-size: 1px;
  padding: 100px 100px;
  background-image: url(${img});
  background-size: contain;
  background-repeat: no-repeat;
  color: transparent;`,
            );
          },
        };
      }
      chalk = window.chalk;
      window.alitadebug = true;
      chalk.hello('Malita', '0.0.6');
      chalk.image(
        'https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ecfbefb4fc8f4a9ca4b3095a8d22752f~tplv-k3u1fbpfcp-watermark.image',
      );
      chalk.log('大家好，我是《挑战21天手写前端框架的产物》');
      chalk.info('作者是陈小聪哦');
      chalk.wait('github: xiaohuoni');
      chalk.warn('感兴趣的朋友可以掘金搜索标题');
      chalk.error('内容主要是挑战日更，所以对于我就是一个附加产物，伤心！');
      chalk.ready('不过没有关系，我还是会努力成长的！gogogo！');
    </script>
  </head>

  <body></body>
</html>
